package com.hp.attendance.dao;

import com.hp.attendance.entity.Card;
import com.hp.attendance.util.BaseDAO;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class CardDao extends BaseDAO {

    public void addCard(Card card) throws SQLException, IOException, ClassNotFoundException {
        String sql="insert into card_supplement values (null,?,?,?,?) ";
        Object[] obj = {card.getEmployee_number(),card.getName(),card.getDate(),card.getType()};
        addOrUpdOrDel(sql,obj);
    }

    public List<Card> queryCard() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException {
        String sql="select * from card_supplement";
        List<Card> cards = queryList(sql, new Object[0], new Card());
        return cards;
    }

    public void passCard(int id) throws SQLException, IOException, ClassNotFoundException {
        String sql="update card_supplement set type='已审批' where id=?";
        Object[] obj={id};
        addOrUpdOrDel(sql,obj);
    }

    public void delCard(int id) throws SQLException, IOException, ClassNotFoundException {
        String sql="delete from card_supplement where id=?";
        Object[] obj={id};
        addOrUpdOrDel(sql,obj);
    }
}
